package org.batch.config.batch.listener;

import org.batch.entity.Trading;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ItemWriteListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Trading对象写入监听器
 *
 * @author LiKun
 * @date 2021/9/28 8:42
 */
@Component
public class TradingWriterListener implements ItemWriteListener<Trading> {
    public static final Logger logger = LoggerFactory.getLogger(TradingWriterListener.class);

    public TradingWriterListener() {
        logger.info("加载数据写入监听器类：TradingWriterListener");
    }

    @Override
    public void beforeWrite(List<? extends Trading> items) {
        logger.info("预计写入{}条数据，其内容为：{}", items.size(), items);
    }

    @Override
    public void afterWrite(List<? extends Trading> items) {
        logger.info("成功写入{}条数据，其内容为：{}", items.size(), items);
    }

    @Override
    public void onWriteError(Exception exception, List<? extends Trading> items) {
        logger.info("{}条数据写入出错，错误原因为：{}，错误数据为：{}", items.size(), exception.getMessage(), items);
    }
}
